#include <stdio.h>

#include "system_information.h"
#include "tss_typedef.h"
#include "tss_error.h"

#include "tddl_measurement.h"
#include "tpm_measurement.h"


TSS_RESULT tddl_measure_initCPUStruct(PCPUINFO* ppCpuInfo){
	TSS_RESULT flag = TDDL_SUCCESS;
	if(initCPUStruct(ppCpuInfo) == 0){
		flag = TDDL_NULL_POINTER;
	}
	return flag;
}


TSS_RESULT tddl_measure_fillCPUStruct(PCPUINFO pCpuInfo){
	TSS_RESULT flag = TDDL_SUCCESS;
	if(pCpuInfo == NULL){
		flag = TDDL_NULL_POINTER;
	}else if(fillCPUStruct(pCpuInfo) == 0){
		flag = TDDL_BAD_RESULT;
	}
	return flag;
}


TSS_RESULT tddl_measure_freeCPUStruct(PCPUINFO *ppCpuInfo){
	TSS_RESULT flag = TDDL_SUCCESS;
	if(*ppCpuInfo == NULL){
		flag = TDDL_NULL_POINTER;
	}else if(freeCPUStruct(ppCpuInfo) == 0){
		flag = TDDL_BAD_RESULT;
	}
	return flag;
}


TSS_RESULT tddl_measure_initSoftStruct(PSOFTINFO* ppSoftInfo){
	TSS_RESULT flag = TDDL_SUCCESS;
	if(initSoftStruct(ppSoftInfo) == 0){
		flag = TDDL_BAD_RESULT;
	}
	return flag;
}


TSS_RESULT tddl_measure_fillSoftStruct(PSOFTINFO pSoftInfo){
	TSS_RESULT flag = TDDL_SUCCESS;
	
	
	if(pSoftInfo == NULL){		
		flag = TDDL_NULL_POINTER;	
	}else if(fillSoftStruct(pSoftInfo) == 0){
		flag = TDDL_BAD_RESULT;	
	}
	
	return flag;
	
}


TSS_RESULT tddl_measure_freeSoftStruct(PSOFTINFO* ppSoftInfo){
	TSS_RESULT flag = TDDL_SUCCESS;
	if(*ppSoftInfo == NULL){
		flag = TDDL_NULL_POINTER;
	}else if(freeSoftStruct(ppSoftInfo)== 0){
		flag = TDDL_BAD_RESULT;
	}
	return flag;
}
TSS_RESULT tddl_measure_program_verify(UINT32 length, BYTE* pProgram){
	TSS_RESULT flag = TDDL_SUCCESS;
	if(pProgram == NULL){
		flag = TDDL_NULL_POINTER;
		return flag;
	}
	if( 0 == 1){
		flag = TDDL_BAD_RESULT;
		return flag;
	}
	printf("TDDL: program test is %s\n", pProgram);
	printf("TDDL: program length is %d\n", length);
	return flag;
}


TSS_RESULT tddl_measure_platform_verify(PCPUINFO pCpuInfo, PSOFTINFO pSoftInfo){

	TSS_RESULT flag = TDDL_SUCCESS;
	
	if(pCpuInfo == NULL || pSoftInfo == NULL){
		flag = TDDL_NULL_POINTER;
		return flag;
	}
	
	if(	strcmp(pCpuInfo->Company,"xd") != 00
		|| strcmp(pCpuInfo->BaseParam, "3.10GHz") != 0
		|| strcmp(pCpuInfo->SerialNumber, "008") != 0
		|| strcmp(pCpuInfo->sha1_hash, "cpu sha1 result") != 0){
		
		flag = TDDL_HARDWARE_ERROR;
		return flag;
	}
	if( strcmp(pSoftInfo->softname, "vx") != 0
		|| strcmp(pSoftInfo->version, "v1.0") != 0
		|| strcmp(pSoftInfo->sha1_hash, "soft sha1 result") != 0){
		flag = TDDL_SOFTWARE_ERROR;
		return flag;
	}
	
	return flag;
}
